Telegram Group & Telegram Channel
🚀 HybridCache

Это решение давней проблемы с разделением между IMemoryCache и IDistributedCache.

🔧 Что даёт HybridCache:
• Единый API для in-memory и distributed кэша
• Настраиваемая сериализация
• Stampede protection (анти-нагрузочная защита)
• Удаление по тегам

🧠 Как работает GetOrCreateAsync:
1. Проверяет локальный и распределённый кэш
2. Если нет — вызывает фабричный метод
3. Кэширует результат и возвращает его

🛡️ Stampede protection: только один запрос на ключ запускает фабрику, остальные ждут — никакой гонки или перегрузки БД.

📌 Сниппет на .NET 9 выглядит так:


app.MapGet("/products/{id}", async (
int id,
HybridCache cache,
ProductDbContext db,
CancellationToken ct) =>
{
var product = await cache.GetOrCreateAsync(
$"product-{id}",
async token =>
{
return await db.Products
.Include(p => p.Category)
.FirstOrDefaultAsync(p => p.Id == id, token);
},
cancellationToken: ct
);

return product is null ? Results.NotFound() : Results.Ok(product);
});


HybridCache доступен для ASP.NET Core

Все разработчики могут воспользоваться HybridCache для более эффективного управления кэшем в приложениях на ASP.NET Core.



tg-me.com/csharp_ci/1386
Create:
Last Update:

🚀 HybridCache

Это решение давней проблемы с разделением между IMemoryCache и IDistributedCache.

🔧 Что даёт HybridCache:
• Единый API для in-memory и distributed кэша
• Настраиваемая сериализация
• Stampede protection (анти-нагрузочная защита)
• Удаление по тегам

🧠 Как работает GetOrCreateAsync:
1. Проверяет локальный и распределённый кэш
2. Если нет — вызывает фабричный метод
3. Кэширует результат и возвращает его

🛡️ Stampede protection: только один запрос на ключ запускает фабрику, остальные ждут — никакой гонки или перегрузки БД.

📌 Сниппет на .NET 9 выглядит так:


app.MapGet("/products/{id}", async (
int id,
HybridCache cache,
ProductDbContext db,
CancellationToken ct) =>
{
var product = await cache.GetOrCreateAsync(
$"product-{id}",
async token =>
{
return await db.Products
.Include(p => p.Category)
.FirstOrDefaultAsync(p => p.Id == id, token);
},
cancellationToken: ct
);

return product is null ? Results.NotFound() : Results.Ok(product);
});


HybridCache доступен для ASP.NET Core

Все разработчики могут воспользоваться HybridCache для более эффективного управления кэшем в приложениях на ASP.NET Core.

BY C# (C Sharp) programming




Share with your friend now:
tg-me.com/csharp_ci/1386

View MORE
Open in Telegram


C C Sharp programming Telegram | DID YOU KNOW?

Date: |

Should You Buy Bitcoin?

In general, many financial experts support their clients’ desire to buy cryptocurrency, but they don’t recommend it unless clients express interest. “The biggest concern for us is if someone wants to invest in crypto and the investment they choose doesn’t do well, and then all of a sudden they can’t send their kids to college,” says Ian Harvey, a certified financial planner (CFP) in New York City. “Then it wasn’t worth the risk.” The speculative nature of cryptocurrency leads some planners to recommend it for clients’ “side” investments. “Some call it a Vegas account,” says Scott Hammel, a CFP in Dallas. “Let’s keep this away from our real long-term perspective, make sure it doesn’t become too large a portion of your portfolio.” In a very real sense, Bitcoin is like a single stock, and advisors wouldn’t recommend putting a sizable part of your portfolio into any one company. At most, planners suggest putting no more than 1% to 10% into Bitcoin if you’re passionate about it. “If it was one stock, you would never allocate any significant portion of your portfolio to it,” Hammel says.

If riding a bucking bronco is your idea of fun, you’re going to love what the stock market has in store. Consider this past week’s ride a preview.The week’s action didn’t look like much, if you didn’t know better. The Dow Jones Industrial Average rose 213.12 points or 0.6%, while the S&P 500 advanced 0.5%, and the Nasdaq Composite ended little changed.

C C Sharp programming from id


Telegram C# (C Sharp) programming
FROM USA